package com.sun.app.process.ajax;

import java.lang.reflect.Method;
import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sun.app.process.BaseProcess;
import com.sun.app.service.ServiceManager;
import com.sun.util.AppResult;

public class AppProcess extends BaseProcess {

	@Override
	public HashMap<String, Object> execute(HttpServletRequest request,
			HttpServletResponse response, HashMap<String, Object> model)
			throws Exception {
		// TODO Auto-generated method stub
		System.out.println("ajax开始运行" + request.getSession().getId());
		AppResult r = new AppResult();
		String serviceName = request.getParameter("serviceName");
		System.out.println(serviceName);
		String methodName = request.getParameter("methodName");
		try {
			ServiceManager servMgr = getServMgr();
			Method getBeanMethod = servMgr.getClass().getMethod(
					"get" + serviceName, null);
			Object beanObject = getBeanMethod.invoke(servMgr, null);
			Method method;

			method = beanObject.getClass().getMethod(methodName,
					HttpServletRequest.class);
			r = (AppResult) method.invoke(beanObject, request);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			model.put("status", 500);
			model.put("e", e.getMessage());
			return model;
		}

		model.put("status", r.getStatus());
		model.put("result", r.getResult());
		model.put("totleCount", r.getTotleCount());
		model.put("msg", r.getMsg());
		System.out.println("ajax开始运行调用结束" + model);
		return model;
	}

}
